package bill;


import com.liCheng.entity.Bill;
import com.liCheng.service.bill.BillService;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.List;

public class BillTest {
    private static Logger logger=Logger.getLogger(BillTest.class);

    /**
     * 模糊查询
     */
    @Test
    public void billTest(){
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-mybatis.xml");
        BillService billService= (BillService) context.getBean("billService");
        List<Bill> billList=new ArrayList<Bill>();
        Bill bill=new Bill();
        bill.setProductName("洗");
        bill.setProviderId(2);
        bill.setId(9);
        billList=billService.findBill(bill);
        for (Bill bill1:billList){
            logger.debug("订单编码："+bill1.getBillCode()
                    +"商品名称："+bill1.getProductName()
                    +"供应商名称："+bill1.getProviderName()
                    +"账单金额："+bill1.getTotalPrice()
                    +"是否付款："+bill1.getIsPayment()
                    +"创建时间："+bill1.getCreationDate()
            );
        }
    }

    /**
     * 添加
     */
    @Test
    public void billAdd(){
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-mybatis.xml");
        BillService billService= (BillService) context.getBean("billService");
        int count=0;
        Bill bill=new Bill();
        bill.setBillCode("打我的微");
        bill.setProductName("色方式");
        bill.setProductDesc("分色分粉色");
        count=billService.addBill(bill);
        if (count>0){
            logger.debug("添加成功");
        }
    }

    /**
     * 修改
     */
    @Test
    public void billUpdate(){
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-mybatis.xml");
        BillService billService= (BillService) context.getBean("billService");
        int count=0;
        Bill bill=new Bill();
        bill.setId(19);
        bill.setBillCode("打我的");
        bill.setProductName("方式");
        bill.setProductDesc("分粉色");
        count=billService.update(bill);
        if (count>0){
            logger.debug("修改成功");
        }
    }

    /**
     * 删除
     */
    @Test
    public void billDel(){
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-mybatis.xml");
        BillService billService= (BillService) context.getBean("billService");
        int count=0;
        Bill bill=new Bill();
        bill.setId(19);
        count=billService.delBill(bill);
        if (count>0){
            logger.debug("删除成功");
        }
    }
}
